package cin.ufpe.assertgroup.main;

import java.io.File;
import java.text.DecimalFormat;
import java.util.List;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.input.SAXBuilder;

import cin.ufpe.assertgroup.model.Structure;
import cin.ufpe.assertgroup.util.StructureCalculator;

public class Main {
	
	private static File dir = new File("../SPLMeter_2/spls-xml");
	
	public static void main(String[] args) throws Exception {
		DecimalFormat df = new DecimalFormat("0.00");
		
		File[] arquivos = dir.listFiles();
		
		//objetos usados no processamento
		SAXBuilder builder;
		Document doc;
		Element root;
		List<Element> filhos;
		Structure estrutura;

		System.out.println("PROJECT;NF;NTOP;NLEAF;CC;CTC;RoV;COC;FOC;NVC;DT");
		for (File file: arquivos) {
			
			builder = new SAXBuilder();
			
			doc = builder.build(file);
			
			//ROOT is the "featuremodel" tag
			root = (Element) doc.getRootElement();
			
			filhos = root.getChildren();
			estrutura = new Structure();
			
			StructureCalculator.calculateMetrics(filhos, estrutura);
			
			System.out.print(file.getName().replace(".xml", "")+";");
			System.out.print(estrutura.getNumberFeatures()+";");
			System.out.print(estrutura.getNumberTopFeatures()+";");
			System.out.print(estrutura.getNumberLeafFeatures()+";");
			System.out.print(estrutura.getCyclomaticComplexity()+";");
			System.out.print(df.format(estrutura.getCrossTreeConstraintsRatio())+";");
			System.out.print(df.format(estrutura.getRatioOfVariability())+";");
			System.out.print(df.format(estrutura.getCoeficientOfConnectivityDensity())+";");
			System.out.print(df.format(estrutura.getFlexibilityOfConfigurationRatio())+";");
			System.out.print("-;");
			System.out.println(estrutura.getDephTree()+";");
		}
	}
	
}
